package com.itzxx.huazhun.network

import android.text.TextUtils
import com.itzxx.huazhun.utils.UserCacheHelper
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

class MyHeadInterceptor : Interceptor {

    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder = chain.request().newBuilder()

        if (!TextUtils.isEmpty(UserCacheHelper.getToken())){
            builder.addHeader("Authorization", "Bearer ${UserCacheHelper.getToken()}").build()
        }

        if (!TextUtils.isEmpty(UserCacheHelper.getTenantId())){
            builder.addHeader("Tenant-id", UserCacheHelper.getTenantId()).build()
        }

        return chain.proceed(builder.build())
    }

}